package com.zh.note.huawei.twohundred.快递业务站;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: zhanghuan
 * @date: 2023/8/12 21:37
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // int num = sc.nextInt();
        // int[][] matrix = new int[num][num];
        // for (int[] row : matrix) {
        //     for (int i = 0; i < row.length; i++) {
        //         row[i] = sc.nextInt();
        //     }
        // }
        int num = 4;
        int[][] matrix = {{1, 1, 0, 0}, {1, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
        Set<Integer> visited = new HashSet<>();
        int count = 0;
        int i = 0;
        while (i < num) {
            if (visited.contains(i)) {
                i++;
                continue;
            }
            Set<Integer> set = new HashSet<>();
            set.add(i);
            dfs(set, i, matrix);
            visited.addAll(set);
            count++;
            i++;
        }
        System.out.println(count);

    }

    private static void dfs(Set<Integer> set, int n, int[][] matrix) {
        for (int j = 0; j < matrix.length; j++) {
            if (set.contains(j)) {
                continue;
            }
            System.out.println(n + ":" + j);
            if (n != j && matrix[n][j] == 1) {
                set.add(j);
                dfs(set, j, matrix);
            }
        }
    }
}
